package com.huiminpay.merchant;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huiminpay.common.cache.util.EncryptUtil;
import com.huiminpay.common.cache.util.QRCodeUtil;
import com.huiminpay.merchant.api.MerchantService;
import com.huiminpay.merchant.dto.MerchantDto;
import jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode;
import org.apache.dubbo.config.annotation.Reference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MerchantApplicationBootstrap.class)
public class TokenTemp {

    @Reference
    MerchantService merchantService;

    //生成token，指定商户id
    @Test
    public void createTestToken() {
        //String s="{\"appId\": \"2016101000652290\", \"rsaPrivateKey\": \"MIIEvQIBADANBgkqhkiG9w0...\", \"alipayPublicKey\": \"MIIBIjANBgkqhkiG9w0BAQ...\",\"notifyUrl\": \"http://127.0.0.1:56010/payment-receiver/alipay-notify\", \"returnUrl\": \"http://127.0.0.1:56010/payment-receiver/alipay-return\", \"url\": \"https://openapi.alipaydev.com/gateway.do\", \"charest\": \"UTF-8\", \"format\": \"json\", \"log_path\": \"/log\", \"signtype\": \"RSA2\"}";
        Long merchantId = 1868485836400521218L;//填写用于测试的商户id
        MerchantDto merchantDTO = merchantService.queryMerchantById(merchantId);
        JSONObject token = new JSONObject();
        token.put("mobile", merchantDTO.getMobile());
        token.put("user_name", merchantDTO.getUsername());
        token.put("merchantId", merchantId);

        String jwt_token = "Bearer " + EncryptUtil.encodeBase64(JSON.toJSONString(token).getBytes());
        System.out.println(jwt_token);
        //Bearer eyJtZXJjaGFudElkIjoxODY1MDYxMDMwMDc0Mjk4MzY5LCJ1c2VyX25hbWUiOiLlrZnlhYbmmIYiLCJtb2JpbGUiOiIxODMzNzI2MDY0NiJ9
    }

}